<template>
  <div>
    <div class="indexUser">
      <div>
        <!-- header  点击 -->
        <headers :userList="userList"></headers>
      </div>
      <div class="bg1 userBox">
        <div class="wrap bgw">
          <div class="box">
            <div class="title">发票信息管理</div>
            <div class="content">
              <div class="txt">
                <div class="fl w">发票类型</div>
                <div class="fl">
                  <p @click="type = 0" :class="{active:type == 0}">
                    <span></span> 个人
                  </p>
                  <p @click="type = 1" :class="{active:type == 1}">
                    <span></span> 企事业单位
                  </p>
                </div>
              </div>
              <div class="txt">
                <div class="fl w">发票抬头</div>
                <div class="fl">
                  <input type="text" v-model="title" />
                </div>
              </div>
              <div class="txt">
                <div class="fl w">税号</div>
                <div class="fl">
                  <input type="text" v-model="tax_no" />
                </div>
              </div>
              <div class="txt">
                <div class="fl w"></div>
                <div class="fl">
                  <button @click="checking()">申请</button>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div>
        <publicBottom></publicBottom>
      </div>
    </div>
  </div>
</template>
<script>
import headers from "./header"; // 头部 TOP 和header
import publicBottom from "@/components/public/public_bottom"; //底部

import { fapiao_list } from "@/request/user";
import { adds } from "@/request/user";
import { usergetinfo } from "@/request/user";

export default {
  components: {
    headers,
    publicBottom
  },
  data() {
    return {
      list: [],
      title: "",
      tax_no: "",
      type: -1,
      userList: [] // 个人信息
    };
  },
  created() {
    let datas = localStorage.getItem("lzyyToken");
    let Athis = this;
    if (datas != null) {
      this.$tokens = datas;
    } else {
      this.$message.error("登录错误，请重新登录");
      setTimeout(function() {
        Athis.$router.replace({ path: "/land" });
      }, 1000);
    }

    this.init();
    this.start();
    // this.state=this.$route.query.state
  },
  methods: {
    checking() {
      if (this.title == "") {
        this.$message.error("请输入 发票抬头");
      } else if (this.tax_no == "") {
        this.$message.error("请输入 税号");
      } else if (this.type == -1) {
        this.$message.error("请选择 发票类型");
      } else {
        this.send();
      }
    },
    send() {
      adds({
        token: this.$tokens,
        title: this.title,
        tax_no: this.tax_no,
        type: this.type
      }).then(res => {
        if (res.code == 1) {
          this.$message({
            message: "修改成功",
            type: "success"
          });
        }
      });
    },
    start() {
      fapiao_list({
        token: this.$tokens
      }).then(res => {
        this.list = res.data;
      });
    },
    init() {
      //   个人信息
      usergetinfo({
        token: this.$tokens
      }).then(res => {
        this.userList = res.data;
      });
    }
  }
};
</script>

<style lang="less" scoped>
.active {
  span {
    background: #4eeec8;
    border: none !important;
  }
  color: #4eeec8;
}
.box {
  font-size: 22px;
  .title {
    height: 69px;
    line-height: 69px;
    padding-left: 44px;
  }
  .content {
    margin-top: 40px;
    min-height: 600px;
    padding-left: 44px;
    > div {
      height: 46px;
      overflow: hidden;
      margin-bottom: 42px;
    }
    p {
      display: inline-block;
      width: 200px;
      position: relative;
      height: 46px;
      text-indent: 50px;
    }
    span {
      position: absolute;
      top: 0;
      left: 0;
      width: 28px;
      height: 28px;
      border: 1px solid rgba(168, 168, 168, 1);
      border-radius: 50%;
    }
  }
  button {
    width: 174px;
    height: 52px;
    font-size: 22px;
  }
  .w {
    width: 160px;
    height: 46px;
  }
  input {
    border: 1px solid #a8a8a8 !important;
    width: 400px;
    height: 46px;
    box-sizing: border-box;
    font-size: 22px;
    text-indent: 10px;
  }
}
</style>